package com.neu.questionnaire_system.controller;

import com.neu.questionnaire_system.beans.ResponseEntity;
import com.neu.questionnaire_system.service.RegisterService;
import com.neu.questionnaire_system.service.impl.RegisterServiceImpl;
import com.neu.questionnaire_system.service.impl.Sample;
import com.neu.questionnaire_system.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

/**
 * @author libo
 * @version 1.0 2022-11-2
 * 注册用接口，重置密码用接口
 */
@RestController
@RequestMapping("/register")
@CrossOrigin
public class RegisterController {

    @Autowired
    private RegisterServiceImpl registerService;

    /**
     * created by libo 确认注册类型，返回包含信息的对象
     * @param map 注册类型
     * @return 封装需要信息的对象
     */
    @RequestMapping(value = "/registerStart")
    public ResponseEntity registerType(@RequestBody Map<String,Object> map){
        return registerService.registerType(map);
    }

    /**
     * created by libo 注册租户，需要传入选择的管理员名字
     * @param map 传入的信息，包含必要的租户名、密码、手机号、所属的管理员
     * @return 返回统一的封装对象
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    @RequestMapping(value = "/registerTenant")
    public ResponseEntity registerTenant(@RequestBody Map<String,Object> map) throws InvocationTargetException, IllegalAccessException {
        return registerService.registerTenant(map);
    }

    /**
     * created by libo 查询是否存在
     * @param map type and name
     * @return 返回统一的封装对象
     */
    @RequestMapping("/resetQueryInfo")
    public ResponseEntity resetQuery(@RequestBody Map<String,Object> map){
        return registerService.resetQueryService(map);
    }

    /**
     * created by libo 重置密码
     * @param map name and password and type
     * @return 返回统一的封装对象
     */
    @RequestMapping("/reset")
    public ResponseEntity reset(@RequestBody Map<String,Object> map){
        return registerService.resetService(map);
    }

    @RequestMapping("/sample")
    public String sample(String phone){
        try {
             Sample.start(phone);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Constants.SUCCESS_CODE;
    }

}
